<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});
Route::get('/hello',function (){
    return 'hello PHP';
});
Route::match(['get','post'],'test1',function (){
    return '通过match()匹配';
});
Route::any('test2',function (){
    return '通过any()匹配';
});
/*路由参数--必选参数*/
Route::get('find/{id}',function ($id){
    return "输入的路由id为".$id;
});
/*路由参数--可选参数*/
Route::get("find2/{id?}",function ($id=0){
    return "输入的id为".$id;
});

//路由查询参数 ?key=value
Route::get("user",function(){
    return "输入的id为".$_GET["id"];
});
//路由分组
Route::group(["prefix"=>"admin"],function (){
    Route::get("login",function (){
        return "/admin/login路由返回的内容";
    });
    Route::get("logout",function (){
        return "/admin/logout";
    });
    Route::get("/user/add/{id}",function ($id){
        return "/admin/user/id".$id;
    });
});
//路由别名
Route::get("/hello/123",function (){
    return "hello";
})->name("hello");



//控制器
Route::get("/controller","TestController@test");
Route::get("/demo22","Admin\TestController@add");

//接受用户输入
Route::get("/test/input","TestController@input");
Route::get("/test/input/{name}","TestController@input2");

Route::get("/demo4","TestController@database");
Route::get("/demo5","TestController@select");
Route::get("/demo6","TestController@del");
Route::get("/demo7","TestController@sql");

//渲染视图
Route::get("render","TestController@show");
Route::get("/demo2",'TestController@demo2');
Route::get("/demo3",'TestController@demo3');
Route::get('/demo','TestController@demo');
Route::get('/test2','TestController@test2');

//自动验证
Route::get('/test/edit','TestController@edit');
Route::get('/test/save','TestController@save');

//页面跳转
Route::get('/abc',function (){
    return redirect('/render');
//    return redirect()->route('demo2');
});
//返回json
Route::get('/data','TestController@data');
//数据分页
Route::get('/data2','TestController@data2');
